﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using YSC_App_WebApi.RestClient;
using YSC_Core.BLL.Domain.CommonModels;
using YSC_Core.BLL.Domain.ViewModels;
using YSC_Services.BLL.Services.Interfaces;

namespace YSC_App_WebApi.Controllers
{
    /// <summary>
    /// 鱼价接口
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class MarketPriceController : ControllerBase
    {
        private IMarketPriceAppServices _rep;

        public MarketPriceController(IMarketPriceAppServices rep)
        {
            this._rep = rep;
        }

        /// <summary>
        /// 市场鱼价列表
        /// </summary>
        /// <param name="input">页码</param>
        /// <param name="datetime">时间</param>
        /// <param name="areaName">地区名称</param>
        /// <param name="fishType">鱼种类别</param>
        /// <param name="fishName">鱼种名称</param>
        /// <param name="areaId">区县Id</param>
        /// <param name="priceType">报价类型0:市场价 1：产地价</param>
        /// <returns>areaId与areaName同时只能传一条</returns>
        [HttpPost]
        [Route("GetMarketPriceAll")]
        public ActionResult GetMarketPriceAll(PaginationRequest input, string datetime, string areaName, string fishType, string fishName, string areaId, int priceType = 0)
        {
            var ret = _rep.GetMarketPriceAll(input.Page, input.PageSize, priceType, datetime, areaName, fishType, fishName, areaId);
            return Ok(ret);
        }

        /// <summary>
        /// 市场鱼价详情
        /// </summary>
        /// <param name="marketPriceId">鱼价Id</param>
        /// <param name="priceType">报价类型0:市场价 1：产地价</param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetMarketPrice")]
        public ActionResult GetMarketPrice(string marketPriceId, int priceType = 0)
        {
            var ret = _rep.GetMarketPrice(marketPriceId, priceType);
            return Ok(ret);
        }

        /// <summary>
        /// 市场鱼价详情_规格对比报表
        /// </summary>
        /// <param name="marketPriceId"></param>
        /// <param name="priceType">报价类型0:市场价 1：产地价</param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetMarketPriceComparedReport")]
        public ActionResult GetMarketPriceComparedReport(string marketPriceId, int priceType = 0)
        {
            var ret = _rep.GetMarketPriceComparedReport(marketPriceId, priceType);
            return Ok(ret);
        }


        /// <summary>
        /// 市场鱼价详情_规格走势报表
        /// </summary>
        /// <param name="marketPriceId">鱼价Id</param>
        /// <param name="type">报表类型:0一周，1三月2一年</param>
        /// <param name="priceType">报价类型0:市场价 1：产地价</param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetMarketPriceTrendReport")]
        public ActionResult GetMarketPriceTrendReport(string marketPriceId, int type = 0, int priceType = 0)
        {
            var ret = _rep.GetMarketPriceTrendReport(marketPriceId, type, priceType);
            return Ok(ret);
        }


        /// <summary>
        /// 市场鱼价详情_消费指导
        /// </summary>
        /// <param name="marketPriceId"></param>
        /// <param name="priceType">报价类型0:市场价 1：产地价</param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetMarketPriceXFZD")]
        public ActionResult GetMarketPriceXFZD(string marketPriceId, int priceType)
        {
            var ret = _rep.GetMarketPriceXFZD(marketPriceId, priceType);
            return Ok(ret);
        }

        /// <summary>
        /// 市场鱼价详情_介绍
        /// </summary>
        /// <param name="marketPriceId"></param>
        /// <param name="priceType">报价类型0:市场价 1：产地价</param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetMarketPriceIntroduction")]
        public ActionResult GetMarketPriceIntroduction(string marketPriceId, int priceType)
        {
            var ret = _rep.GetMarketPriceIntroduction(marketPriceId, priceType);
            return Ok(ret);
        }

        /// <summary>
        /// 用户报价历史记录
        /// </summary>
        /// <param name="input"></param>
        /// <param name="MarketId">市场Id</param>
        /// <param name="dateTime">添加时间</param>
        /// <returns></returns>
        [HttpPost]
        [Route("GetMarketPriceHistoryAll")]
        [TestAuthorize("User_Edit")]
        public ActionResult GetMarketPriceHistoryAll(PaginationRequest input, string MarketId, string dateTime)
        {
            var claimsAll = HttpContext.User.Claims.Select(p => new { p.Type, p.Value });
            var items = claimsAll.FirstOrDefault(p => p.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier");

            var userid = string.Empty;

            if (items != null)
                userid = items.Value;

            var ret = _rep.GetMarketPriceHistoryAll(input.Page, input.PageSize, userid, MarketId, dateTime);
            return Ok(ret);
        }

        /// <summary>
        /// 市场鱼价新增
        /// </summary>
        /// <param name="modelAll"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("AddMarketPrice")]
        [TestAuthorize("User_Edit")]
        public ActionResult AddMarketPrice(List<MarketPriceModel> modelAll)
        {
            var claimsAll = HttpContext.User.Claims.Select(p => new { p.Type, p.Value });
            var items = claimsAll.FirstOrDefault(p => p.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier");

            var userid = string.Empty;

            if (items != null)
                userid = items.Value;

            var ret = _rep.AddMarketPrice(modelAll, userid);
            return Ok(ret);
        }


        /// <summary>
        /// 市场鱼价新增(非认证)
        /// </summary>
        /// <param name="modelAll"></param>
        /// <returns>PricType:0 市场 1： 产地</returns>
        [HttpPost]
        [Route("AddMarketPriceNOAttest")]
        [TestAuthorize("User_Edit")]
        public ActionResult AddMarketPriceNOAttest(List<MarketPriceModel> modelAll)
        {
            var claimsAll = HttpContext.User.Claims.Select(p => new { p.Type, p.Value });
            var items = claimsAll.FirstOrDefault(p => p.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier");

            var userid = string.Empty;

            if (items != null)
                userid = items.Value;
            var ret = _rep.AddMarketPriceNOAttest(modelAll, userid);
            return Ok(ret);
        }


    }
}